<%@page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<!doctype html>
<html>
<head>
<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
	font-size: 12px;
}
</style>
</head>
<body class="gray-bg">

	<!-- 隐藏域 -->
	<input type="hidden" value="${replaceId}" id="replaceId"
		name="replaceId" />
	<input type="hidden" value="${busiId}" id="busiId" name="busiId" />
	<input type="hidden" value="${modeId}" id="modeId" name="modeId" />
	<input type="hidden" id="dkId" />
	<input type="hidden" id="bbusiId" />
	<!-- 隐藏域 -->

	<div class="container creditbody">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;垫款调整B</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="buttonfixed" style="display: none;" id="buttonfixed">
			<button type="button" id="save" style="display: none;"
				class="btn dpbtn_blue" onclick="saveOrUpdate();">保存</button>
			<button type="button" id="update" style="display: none;"
				class="btn dpbtn_blue" onclick="saveOrUpdate();">修改</button>
		</div>
		<div class="ibox-content ibox-con">
			<%@include file="/jsp/common_yw_include.jsp"%>
			<div class="business-manwife">业务进程</div>
			<div class="business-padding" id="">
				<table class="yw-course">
					<thead>
						<tr>
							<th id="added_status1" equal="0" class="splztab bg-grey">按揭日报表</th>
							<th id="dianzi" equal="30" class="splztab bg-grey">申请垫资
								</li>
							<th id="M_cwshy" equal="50" class="splztab bg-grey">财务审核1</th>
							<th id="M_cwshe" equal="200" class="splztab bg-grey">财务审核2</th>
							<th id="caiwudiankuan" class="splztab bg-grey">财务垫款</th>
							<th id="" class="splztab bg-grey">垫款调整A</th>
							<th id="" class="splztab bg-grey">申请垫款调整Ｂ</th>
							<th id="" class="splztab bg-grey">垫款调整Ｂ审核</th>
							<th id="" class="splztab bg-green">垫款调整Ｂ</th>
							<th id="" class="splztab">财务退款</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		<div class="business-manwife">协议资料</div>
		<%@include file="/jsp/xieyi_zi_liao.jsp"%>

		<div class="business-manwife">申请垫资信息</div>
		<div class="tche-padding">
			<table cellpadding="0" cellspacing="0" border="0" class="infor-table">
				<tr>
					<td align="right"><label class="control-label np">提车时间：</label>
					</td>
					<td>
						<div class="control-div np" id="dateFist">
							<fmt:formatDate value='${ywFundApply.dateFist}'
								pattern='yyyy-MM-dd HH:mm' />
						</div>
					</td>
				</tr>
			</table>
			<ul class="zxsearch-ulsd" style="margin-top: 15px;">
				<li class="zxsearch-ulli" style="margin: 0px;">信息备注：</li>
				<li class="zxsearch-ullib">${ywFundApply.remarks }</li>
			</ul>
		</div>

		<div class="business-manwife">费用明细</div>
		<div class="tche-padding">
			<table cellpadding="0" cellspacing="0" border="0" class="thead-table padding-wangge">
				<thead class="thead-a">
					<tr>
						<th class="warn-red-bold">贷款本金</th>
						<th class="warn-red-bold">签约贷款额</th>
						<c:if test="${!empty fundItems_ }">
							<c:forEach items="${fundItems_ }" var="fundItem_" varStatus="status">
								<th class="warn-red-bold">${fundItem_.name }</th>
							</c:forEach>
						</c:if>
					</tr>
				</thead>
				<tbody class="tbody-a">
					<tr>
						<td class="zxyjred"><fmt:formatNumber type="number" value="${empty ywBusinessLoan.loanAmount ? 0 : ywBusinessLoan.loanAmount}" pattern="0.00" maxFractionDigits="2" /></td>
						<td class="zxyjred"><fmt:formatNumber type="number" value="${empty ywBusinessLoan.signLoanAmount ? 0 :  ywBusinessLoan.signLoanAmount}" pattern="0.00" maxFractionDigits="2" /></td>
						<c:if test="${!empty fundItems_ }">
							<c:forEach items="${fundItems_ }" var="fundItem_" varStatus="status">
								<td class="zxyjred"><fmt:formatNumber type="number" value="${empty fundItem_.feeCount ? 0 : fundItem_.feeCount}" pattern="0.00" maxFractionDigits="2" /></td>
							</c:forEach>
						</c:if>
					</tr>
				</tbody>
			</table>
			<c:choose>
				<c:when test="${!empty fundItems }">
					<ul class="thead-tableul">
						<c:forEach items="${fundItems }" var="cwFundItem"
							varStatus="status">
							<c:if test="${status.index % 7 == 0 }">
								<li>
									<table cellpadding="0" cellspacing="0" border="0"
										class="thead-table">
										<thead class="thead-a">
											<tr>
												<th></th>
												<th>应收</th>
												<th>实收</th>
											</tr>
										</thead>
										<tbody class="tbody-a">
												</c:if>
												<tr>
													<td
														<c:if test="${cwFundItem.key == '03'}"> style="color:#FC1515;"</c:if>
														<c:if test="${cwFundItem.key == '25'}"> style="color:#FC1515;"</c:if>>${cwFundItem.name }
													</td>
													<td <c:if test="${cwFundItem.key == '03'}"> style="color:#FC1515;"</c:if>
														<c:if test="${cwFundItem.key == '25'}"> style="color:#FC1515;"</c:if> id="fee_td_${cwFundItem.key }">
														<fmt:formatNumber type="number" value="${cwFundItem.feeCount }" pattern="0.00" maxFractionDigits="2" /></td>
													<td <c:if test="${cwFundItem.key == '03'}"> style="color:#FC1515;"</c:if>
														<c:if test="${cwFundItem.key == '25'}"> style="color:#FC1515;"</c:if> id="remit_td_${cwFundItem.key }">
														<fmt:formatNumber type="number" value="${cwFundItem.remitCount }" pattern="0.00" maxFractionDigits="2" /></td>
												</tr>
												<c:if test="${status.index % 7 == 6  || status.last}">
											</tbody>
									</table>
								</li>
							</c:if>
						</c:forEach>
					</ul>
				</c:when>
				<c:otherwise>
        			没有收费项目
        		</c:otherwise>
			</c:choose>
			<ul class="thead-tableul">
				<li>
					<table cellpadding="0" cellspacing="0" border="0"
						class="thead-table">
						<thead class="thead-a">
							<tr>
								<th></th>
								<th>应收</th>
								<th>实收</th>
							</tr>
						</thead>
						<tbody class="tbody-a">
							<tr>
								<td class="npb style-red">应收合计</td>
								<td><fmt:formatNumber type="number"
										value="${fundTotal.feeCount }" pattern="0.00"
										maxFractionDigits="2" /></td>
								<td><fmt:formatNumber type="number"
										value="${fundTotal.remitCount }" pattern="0.00"
										maxFractionDigits="2" /></td>
							</tr>
						</tbody>
					</table>
				</li>
			</ul>
		</div>
		<div class="business-manwife">垫款调整信息</div>
		<div class="tche-padding">
			<table cellpadding="0" cellspacing="0" border="0"
				class="thead-tabletz">
				<thead class="thead-a">
					<tr>
						<th></th>
						<th>原值</th>
						<th>新值</th>
						<th>调整值</th>
					</tr>
				</thead>
				<tbody class="tbody-a">
					<tr>
						<td>签约贷款额</td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="signLoanAmountOld" name="signLoanAmountOld"
							value="${ywBusiness.signLoanAmount}" /></td>
						<td><input onkeyup="counta();" class="tbody-control" readonly="readonly"
							type="text" id="signLoanAmountNew" name="signLoanAmountNew" readonly="readonly" /></td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="signLoanAmountAdjust" name="signLoanAmountAdjust" /></td>
					</tr>
					<tr>
						<td>实际贷款额</td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="loanAmountOld" name="loanAmountOld"
							value="${ywBusiness.realLoanAmount }" /></td>
						<td><input onkeyup="countb();" class="tbody-control" readonly="readonly"
							type="text" id="loanAmountNew" name="loanAmountNew" readonly="readonly"/></td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="loanAmountAdjust" name="loanAmountAdjust" /></td>
					</tr>
					<tr>
						<td>经销商返利</td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="rebateDealerOld" name="rebateDealerOld"
							value="${ywFees.rebateDealer}" /></td>
						<td><input onkeyup="countc();" class="tbody-control" readonly="readonly"
							type="text" id="rebateDealerNew" name="rebateDealerNew" readonly="readonly"/></td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="rebateDealerAdjust" name="rebateDealerAdjust" /></td>
					</tr>
					<tr>
						<td>分公司展业费</td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="rebateProvinceOld" name="rebateProvinceOld"
							value="${ywFees.rebateProvince}" /></td>
						<td><input onkeyup="countd();" class="tbody-control" readonly="readonly"
							type="text" id="rebateProvinceNew" name="rebateProvinceNew" readonly="readonly"/></td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="rebateProvinceAdjust" name="rebateProvinceAdjust" /></td>
					</tr>
					<tr>
						<td>区域&业务员展业费</td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="rebateAreaOld" name="rebateAreaOld"
							value="${ywFees.rebateArea}" /></td>
						<td><input onkeyup="counte();" class="tbody-control" readonly="readonly"
							type="text" id="rebateAreaNew" name="rebateAreaNew" readonly="readonly"/></td>
						<td><input class="tbody-control" readonly="readonly"
							type="text" id="rebateAreaAdjust" name="rebateAreaAdjust" /></td>
					</tr>

				</tbody>
			</table>
			<table cellpadding="0" cellspacing="0" border="0" class="infor-table">
				<tr>
					<td align="right"><label class="control-label np">返利方式：</label>
					</td>
					<td>
						<div class="control-div np" id="">${empty ywFees.rebateTypeDisplay ? '-' : ywFees.rebateTypeDisplay}
					</td>
				</tr>
			</table>
		</div>

		<form class="form-horizontal" id="commentForm">
			<div class="business-manwife">财务调整信息</div>
			<div class="tche-padding">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">调整金额：</label>
						</td>

						<td><input class="form-control" type="text" id="amountAdjust"
							name="amountAdjust" required="required" placeholder="调整金额(必填)" />
						</td>
						<td><select class="form-control" id="remitAdjustType"
							name="remitAdjustType" style="width: 80px;">
								<option value="1">收款</option>
								<option value="2">付款</option>
						</select></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">打款时间：</label>
						</td>
						<td><input class="laydate-icon form-control"
							placeholder="打款时间(必填)" required="required" type="text"
							id="timeRemit" name="timeRemit" onclick="laydate();" /></td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">到账时间：</label>
						</td>
						<td><input class="laydate-icon form-control"
							placeholder="到账时间" type="text" id="timeArrive" name="timeArrive"
							onclick="laydate();" /></td>
						<td align="right"><label class="control-label np">财务审核人：</label>
						</td>
						<td><input id="nameAuditor" name="nameAuditor"
							placeholder="财务审核人(必填)" required="required" class="form-control" />
						</td>
					</tr>
					<tr>
						<td align="right"><label class="control-label np">财务审核时间：</label>
						</td>
						<td><input class="laydate-icon form-control"
							placeholder="财务审核时间" type="text" id="timeAudit" name="timeAudit"
							onclick="laydate();" /></td>
						<td align="right"><label class="control-label np">财务档案编号：</label>
						</td>
						<td><input id="financialRecordsNumber"
							placeholder="财务档案编号(必填)" required="required"
							name="financialRecordsNumber" placeholder="财务档案编号"
							class="form-control" /></td>
					</tr>
				</table>
			</div>
			<div class="business-manwife">经办信息</div>
			<div class="tche-padding">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">经办人：</label>
						</td>
						<td><input class="form-control" type="text" id="uname"
							name="uname" placeholder="经办人" value="${current_user_key.uname}"
							readonly="readonly" /></td>
						<td align="right"><label class="control-label np">经办时间：</label>
						</td>
						<td><input id="jbTime" name="jbTime" placeholder="经办时间" readonly="readonly"
							class="laydate-icon form-control" onclick="laydate();" /></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>
	<!-- layerDate plugin javascript -->
	<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
	<!-- custom js -->
	<%@include
		file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>
	<script type="text/javascript"></script>
	<!-- 
 	    作者：程立勇
 	   描述：js脚本
 	 -->
	<script type="text/javascript">
 	var counta=function(){
 		  var signLoanAmountOld=$("#signLoanAmountOld").val()==""?"0":$("#signLoanAmountOld").val();
 		  var signLoanAmountNew=$("#signLoanAmountNew").val()==""?"0":$("#signLoanAmountNew").val();
 		  $("#signLoanAmountAdjust").val((parseFloat(signLoanAmountNew)-parseFloat(signLoanAmountOld)).toFixed(2));
 	  }
 	var countb=function(){
 		  var loanAmountOld=$("#loanAmountOld").val()==""?"0":$("#loanAmountOld").val();
 		  var loanAmountNew=$("#loanAmountNew").val()==""?"0":$("#loanAmountNew").val();
 		  $("#loanAmountAdjust").val((parseFloat(loanAmountNew)-parseFloat(loanAmountOld)).toFixed(2));
 	}
 	var countc=function(){
 		  var rebateDealerOld=$("#rebateDealerOld").val()==""?"0":$("#rebateDealerOld").val();
 		  var rebateDealerNew=$("#rebateDealerNew").val()==""?"0":$("#rebateDealerNew").val();
 		  $("#rebateDealerAdjust").val((parseFloat(rebateDealerNew)-parseFloat(rebateDealerOld)).toFixed(2));
 	}
 	var countd=function(){
 		  var rebateProvinceOld=$("#rebateProvinceOld").val()==""?"0":$("#rebateProvinceOld").val();
 		  var rebateProvinceNew=$("#rebateProvinceNew").val()==""?"0":$("#rebateProvinceNew").val();
 		  $("#rebateProvinceAdjust").val((parseFloat(rebateProvinceNew)-parseFloat(rebateProvinceOld)).toFixed(2));
 	}
 	var counte=function(){
 		  var rebateAreaOld=$("#rebateAreaOld").val()==""?"0":$("#rebateAreaOld").val();
 		  var rebateAreaNew=$("#rebateAreaNew").val()==""?"0":$("#rebateAreaNew").val();
 		  $("#rebateAreaAdjust").val((parseFloat(rebateAreaNew)-parseFloat(rebateAreaOld)).toFixed(2));
 	}
 	$(function(){
 		getDataInfoByBusiId();
 		
        $("#commentForm").validate({
        	 rules: {
        		 amountAdjust:{
        			 allMoney:true
        		 }
        	 },
		    //重写showErrors
	        showErrors: function (errorMap, errorList) {
	        	$.each(errorList, function (i, v) {
	        		layer.tips(v.message, v.element, { time: 1500 });
	        		
	                return false;
	            });
	        },
	        /* 失去焦点时验证 */
	        onfocusout: function(element) {$(element).valid(); },
	        /*  键盘抬起不验证 */
	        onkeyup:false,
	    });
	});
 	
 	var getDataInfoByBusiId=function(){
 		var data={};
 		data.busiId=$.getUrlData("id");
 		$.dpAjax({
    		url:'${basePath}/CwRemitAdjustbSubController/list',
    		data:data,
				success: function(datas){
    			  if(datas.flag == "100100")
				  {
    				  if(datas.result.rows.length>0){
    					  var data=datas.result.rows[0];
    					  $("#bbusiId").val(data.busiId);
    					  $("#dkId").val(data.remitAdjustbId);
    					  $("#buttonfixed").show();
    					  $("#update").show();
    					  $("#save").hide();
    					  $("#amountAdjust").val(data.amountAdjust);
    					  var t1 = document.getElementById("remitAdjustType");   
    		      	        for(i=0;i<t1.length;i++){//给select赋值  
    		      	            if(data.remitAdjustType==t1.options[i].text){  
    		      	                t1.options[i].selected=true  
    		      	            }  
    		      	        }
    						$("#timeRemit").val(data.timeRemit);
    						$("#timeArrive").val(data.timeArrive);
    						$("#nameAuditor").val(data.nameAuditor);
    						$("#timeAudit").val(data.timeAudit);
    						$("#financialRecordsNumber").val(data.financialRecordsNumber);
    						$("#jbTime").val(data.jbTime);
    						$("#uname").val(data.modifierName);
    						$("#signLoanAmountOld").val(data.signLoanAmountOld);
    						$("#loanAmountOld").val(data.loanAmountOld);
    						$("#signLoanAmountNew").val(data.signLoanAmountNew);
    						$("#loanAmountNew").val(data.loanAmountNew);
    						
    						$("#rebateAreaOld").val(data.rebateAreaOld);
    						$("#rebateAreaNew").val(data.rebateAreaNew);
    						$("#rebateAreaAdjust").val(data.rebateAreaAdjust);
    						
    						$("#rebateProvinceAdjust").val(data.rebateProvinceAdjust);
    						$("#rebateProvinceOld").val(data.rebateProvinceOld);
    						$("#rebateProvinceNew").val(data.rebateProvinceNew);
    						
    						$("#rebateDealerNew").val(data.rebateDealerNew);
    						$("#rebateDealerOld").val(data.rebateDealerOld);
    						$("#rebateDealerAdjust").val(data.rebateDealerAdjust);
    						$("#signLoanAmountAdjust").val(data.signLoanAmountAdjust);
    						$("#loanAmountAdjust").val(data.loanAmountAdjust);
    				  }else{
    					  $("#buttonfixed").show();
    					  $("#save").show();
    					  $("#update").hide();
    				  }
    				  layer.msg('执行成功！', {icon: 6});
					  return;
				  }
				  if(datas.flag == "100200")
                  {
					  $.fn.showDatas({"datas":datas});
                	  return;
                  }
            }
    	});
 	}
 	var saveOrUpdate=function(){
		var data={};
		var dkId=$("#dkId").val();
		var url='${basePath}/CwRemitAdjustBController/save';
		if(dkId!=""){
			data.id=dkId;
			url='${basePath}/CwRemitAdjustBController/modify';
		}
// 		data.signLoanAmountNew=$("#signLoanAmountNew").val();
// 		data.loanAmountNew=$("#loanAmountNew").val();
// 		data.rebateDealer=$("#rebateDealer").val();
// 		data.rebateProvince=$("#rebateProvince").val();
// 		data.rebateArea=$("#rebateArea").val();
		data.cusId=$("#customerId").val();
		data.busiId=$.getUrlData("id");
		data.amountAdjust=$("#amountAdjust").val();
		data.remitAdjustType=$('#remitAdjustType option:selected').text();
		data.timeRemit=$("#timeRemit").val();
		data.timeArrive=$("#timeArrive").val();
		data.nameAuditor=$("#nameAuditor").val();
		data.timeAudit=$("#timeAudit").val();
		data.financialRecordsNumber=$("#financialRecordsNumber").val();
		var validstatus = $("#commentForm").valid();
		if(validstatus){
			$.dpAjax({
	    		url:url,
	    		data:data,
					success: function(datas){
	    			  if(datas.flag == "100100")
					  {
	    				  layer.msg('执行成功！', {icon: 6});
						  return;
					  }
					  if(datas.flag == "100200")
	                  {
						  $.fn.showDatas({"datas":datas});
	                	  return;
	                  }
	            }
	    	});
		}else{
			layer.msg('有验证未通过，请仔细检查！', {icon: 5});
		}
 	}
	 	
	</script>
</body>
</html>
